package com.iss.yunpan.service.impl;
import com.iss.yunpan.dao.IndexDao;
import com.iss.yunpan.entity.Users;
import com.iss.yunpan.service.IndexService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private IndexDao dao;
    @Override
    public Users getUsersByUsernameAndPassword(String username, String password) {
        return dao.getUsersByUsernameAndPassword(username,password);
    }

    @Override
    public boolean insertUser(Users users) {
        try {
            if (users != null) {

                if(!"".equals(users.getUserId())
                        && !"".equals(users.getPassword())
                        && !"".equals(users.getRealName()))
                {
                    users.setCreateTime(new Date());
                    dao.insertUser(users);
                    return true;
                }
            }
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }
        return false;
    }

    @Override
    public boolean checkUserByUserId(String userId) {
         try {
             Users users = dao.getUsersByUserId(userId);
             if (users != null && !users.getUserId().equals("")) {
                 return true;
             }
         }catch (Exception e){
             e.printStackTrace();
         }
        return false;
    }

    @Override
    public boolean modifyPassword(String userId, String newPassword) {
        try {
            dao.modifyPassword(userId, newPassword);
            return true;
        }catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
